﻿namespace PMS.Client.FrmUserPositionLevel
{
    using PMS.BLL;
    using PMS.Model;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Linq;
    using System.Reflection;
    using System.Windows.Forms;

    public class FrmPositionLevelLogCheck : Form
    {
        private Button btnCancel;
        private Button btnSave;
        private Button btnUnpass;
        private IContainer components = null;
        private Label label1;
        private Label label2;
        private UserChangeLog log = null;
        private UserChangeLogBLL logbll = new UserChangeLogBLL();
        private int logid = 0;
        private TextBox txtRemark;
        private TextBox txtUsername;
        private UserBLL userbll = new UserBLL();

        public FrmPositionLevelLogCheck(int logid)
        {
            this.InitializeComponent();
            this.logid = logid;
            this.log = this.logbll.GetModel(logid);
            this.txtUsername.Text = this.log.IUserName;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.logbll.Check(this.logid, "审核通过", this.txtRemark.Text))
            {
                User model = this.userbll.GetModel(this.log.UserID);
                List<PropertyInfo> source = this.log.GetType().GetProperties().ToList<PropertyInfo>();
                Func<PropertyInfo, bool> predicate = null;
                foreach (PropertyInfo p in model.GetType().GetProperties())
                {
                    if (predicate == null)
                    {
                        predicate = f => f.Name == p.Name;
                    }
                    object obj2 = source.FirstOrDefault<PropertyInfo>(predicate).GetValue(this.log, null);
                    if ((obj2 != null) && (obj2.ToString() != ""))
                    {
                        p.SetValue(model, obj2, null);
                    }
                }
                if (this.userbll.Update(model))
                {
                    SyslogBLL.Write("审核用户信息", "用户定岗审核通过");
                    base.DialogResult = DialogResult.OK;
                }
                else
                {
                    this.logbll.Check(this.logid, "未审核", "");
                    MessageBox.Show("审核失败！");
                }
            }
        }

        private void btnUnpass_Click(object sender, EventArgs e)
        {
            SyslogBLL.Write("审核用户信息", "用户定岗审核未通过");
            this.logbll.Check(this.logid, "审核未通过", this.txtRemark.Text);
            base.DialogResult = DialogResult.OK;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(FrmPositionLevelLogCheck));
            this.btnUnpass = new Button();
            this.btnCancel = new Button();
            this.btnSave = new Button();
            this.txtRemark = new TextBox();
            this.label2 = new Label();
            this.txtUsername = new TextBox();
            this.label1 = new Label();
            base.SuspendLayout();
            this.btnUnpass.BackColor = Color.White;
            this.btnUnpass.FlatStyle = FlatStyle.Popup;
            this.btnUnpass.Location = new Point(0xb7, 210);
            this.btnUnpass.Name = "btnUnpass";
            this.btnUnpass.Size = new Size(0x4b, 0x17);
            this.btnUnpass.TabIndex = 0x1d;
            this.btnUnpass.Text = "不通过";
            this.btnUnpass.UseVisualStyleBackColor = false;
            this.btnUnpass.Click += new EventHandler(this.btnUnpass_Click);
            this.btnCancel.BackColor = Color.White;
            this.btnCancel.FlatStyle = FlatStyle.Popup;
            this.btnCancel.Location = new Point(0x11f, 210);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(0x4b, 0x17);
            this.btnCancel.TabIndex = 0x1c;
            this.btnCancel.Text = "关闭";
            this.btnCancel.UseVisualStyleBackColor = false;
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
            this.btnSave.BackColor = Color.White;
            this.btnSave.FlatStyle = FlatStyle.Popup;
            this.btnSave.Location = new Point(0x4d, 210);
            this.btnSave.Name = "btnSave";
            this.btnSave.Size = new Size(0x4b, 0x17);
            this.btnSave.TabIndex = 0x1b;
            this.btnSave.Text = "通过";
            this.btnSave.UseVisualStyleBackColor = false;
            this.btnSave.Click += new EventHandler(this.btnSave_Click);
            this.txtRemark.Anchor = AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
            this.txtRemark.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.txtRemark.BorderStyle = BorderStyle.FixedSingle;
            this.txtRemark.Location = new Point(0x4d, 0x47);
            this.txtRemark.Multiline = true;
            this.txtRemark.Name = "txtRemark";
            this.txtRemark.Size = new Size(0x11d, 120);
            this.txtRemark.TabIndex = 0x1a;
            this.label2.AutoSize = true;
            this.label2.Location = new Point(0x12, 0x4a);
            this.label2.Name = "label2";
            this.label2.Size = new Size(0x35, 12);
            this.label2.TabIndex = 0x19;
            this.label2.Text = "审核备注";
            this.txtUsername.Anchor = AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
            this.txtUsername.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.txtUsername.BorderStyle = BorderStyle.FixedSingle;
            this.txtUsername.Enabled = false;
            this.txtUsername.Location = new Point(0x4d, 0x1d);
            this.txtUsername.Name = "txtUsername";
            this.txtUsername.ReadOnly = true;
            this.txtUsername.Size = new Size(0xb5, 0x15);
            this.txtUsername.TabIndex = 0x18;
            this.label1.AutoSize = true;
            this.label1.Location = new Point(0x12, 0x20);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x35, 12);
            this.label1.TabIndex = 0x17;
            this.label1.Text = "人员名称";
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = AutoScaleMode.Font;
            this.BackColor = Color.FromArgb(0xa4, 0xc4, 0xeb);
            base.ClientSize = new Size(0x19c, 0xf5);
            base.Controls.Add(this.btnUnpass);
            base.Controls.Add(this.btnCancel);
            base.Controls.Add(this.btnSave);
            base.Controls.Add(this.txtRemark);
            base.Controls.Add(this.label2);
            base.Controls.Add(this.txtUsername);
            base.Controls.Add(this.label1);
            base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "FrmPositionLevelLogCheck";
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "定岗审核";
            base.ResumeLayout(false);
            base.PerformLayout();
        }
    }
}

